package com.piccolo.wrapper.client.component.Overlay;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.JsArray;
import com.piccolo.wrapper.client.component.PBounds;
import com.piccolo.wrapper.client.component.PCanvas;
import com.piccolo.wrapper.client.component.PNode;
import com.piccolo.wrapper.client.component.PPoint;
import com.piccolo.wrapper.client.component.PRoot;
import com.piccolo.wrapper.client.component.PTransform;
import com.piccolo.wrapper.client.component.JSNI.PNodeJSNI;
import com.piccolo.wrapper.client.handler.PBasicInputEventHandler;

public class PNodeOverlay extends Overlay
{
	private static PNodeJSNI impl = new PNodeJSNI(); 
	
	protected PNodeOverlay(){}

	public static PNodeOverlay create()
	{
		return impl.create();
	}

	public static PNodeOverlay create(String fillStyle, PBounds bounds) 
	{
		return impl.create(fillStyle, bounds.getOverlay());
	}

	public final List<PNode> getChildren()
	{
		List<PNode> children = new ArrayList<PNode>();
		JsArray<PNodeOverlay> overlays = impl.getChildren(this);
		for (int i = 0; i<overlays.length(); i++)
		{
			children.add(new PNode(overlays.get(i)));
		}
		return children;
	}

	public final void addChild(PNode child) 
	{ 
		impl.addChild(this, child.getOverlay()); 
	}

	public final void translate(double x, double y) 
	{ 
		impl.translate(this, x, y); 
	}

	public final void scale(double displayScale) 
	{
		impl.scale(this, displayScale);
	}
	
	public final void setDisplayScale(double displayScale) 
	{
		impl.setDisplayScale(this, displayScale);
	}

	public final double getDisplayScale() 
	{
		return impl.getDisplayScale(this);
	}

	public final void addClickListener(PBasicInputEventHandler handler) 
	{
		impl.addClickListener(this, handler);	
	}

	public final void addMouseOverListener(PBasicInputEventHandler handler) 
	{
		impl.addMouseOverListener(this, handler);	
	}
	
	public final void addMouseOutListener(PBasicInputEventHandler handler) 
	{
		impl.addMouseOutListener(this, handler);	
	}
	
	public final PTransform getGlobalTransform()
	{
		return new PTransform(impl.getGlobalTransform(this));
	}

	public final PBounds getGlobalFullBounds()
	{
		return new PBounds(impl.getGlobalFullBounds(this));
	}

	public final void paintAfterChildren(PCanvas canvas) 
	{
		impl.paintAfterChildren(this, canvas.getOverlay());
	}

	public final PBounds getBounds() 
	{
		return new PBounds(impl.getBounds(this));
	}

	public final void rotate(double theta) 
	{
		impl.rotate(this, theta);
	}
	
	public final void setTransform(PTransform transformation) 
	{ 
		impl.setTransform(this, transformation.getOverlay()); 
	}
	
	public final PRoot getRoot() 
	{ 
		return new PRoot(impl.getRoot(this)); 
	}

	public final void setBounds(PBounds bounds) 
	{
		impl.setBounds(this, bounds.getOverlay());
	}

	public final void removeChild(PNode child) 
	{
		impl.removeChild(this, child.getOverlay());
	}

	public final void animateToTransform(PTransform transform, double duration) 
	{
		impl.animateToTransform(this, transform.getOverlay(), duration);
	}

	public final PBounds getFullBounds() 
	{
		return new PBounds(impl.getFullBounds(this));
	}

	public final void invalidateBounds() 
	{
		impl.invalidateBounds(this);
	}

	public final PTransform localToParent(PTransform target) 
	{
		return new PTransform(impl.localToParent(this, target.getOverlay()));
	}

	public final PPoint localToParent(PPoint target) 
	{
		return new PPoint(impl.localToParent(this, target.getOverlay()));
	}

	public final PBounds localToParent(PBounds target) 
	{
		return new PBounds(impl.localToParent(this, target.getOverlay()));
	}

	public final PTransform parentToLocal(PTransform target) 
	{
		return new PTransform(impl.parentToLocal(this, target.getOverlay()));
	}

	public final PPoint parentToLocal(PPoint target) 
	{
		return new PPoint(impl.parentToLocal(this, target.getOverlay()));
	}

	public final PBounds parentToLocal(PBounds target) 
	{
		return new PBounds(impl.parentToLocal(this, target.getOverlay()));
	}

	public final void moveToFront() 
	{
		impl.moveToFront(this);
	}

	public final void moveToBack() 
	{
		impl.moveToBack(this);
	}
}
